#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>


bool isValid(char* s) 
{
    int len = strlen(s);
    int * nums = malloc(sizeof(int)*len);
    int count = 0;
   
    if(len % 2 != 0)
    {
        return false;
    }
    if(s[0] == ')' || s[0] == ']' || s[0] == '}')
    {
        return false;
    }
    for(int i = 0;i < len;i++)
    {
        switch(s[i])
        {
            case '(':
                nums[count++] = 1;
                break;
            case '[':
                nums[count++] = 2;
                break;
            case '{':
                nums[count++] = 3;
                break;
            case ')':
                if(nums[--count] != 1)
                    return false;
                else
                    nums[count] = 0;
                break;
            case ']':
                if(nums[--count] != 2)
                    return false;
                else
                    nums[count] = 0;
                break;
            case '}':
                if(nums[--count] != 3)
                    return false;
                else
                    nums[count] = 0;
                break;
        }
    }
    if(nums[0] == 0)
        return true;
    else
        return false;
}

int main()
{
    char s[] = "({[](}))";
    if(isValid(s))
        printf("true\n");
    else
        printf("false\n");

    return 0;
}